<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>版本管理</title>
<!-- 导入jquery核心类库 -->
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<!-- 导入easyui类库 -->
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/ext/portal.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/css/default.css">	
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.portal.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.cookie.js"></script>
<script
	src="${pageContext.request.contextPath }/js/easyui/locale/easyui-lang-zh_CN.js"
	type="text/javascript"></script>

<script type="text/javascript">
function doAdd(){
	//alert("增加...");
	//$("input[name='sId']").val('-1');
	$('#addStandardWindow').form('clear');
	$('#addStandardWindow *').trigger('blur');// 离焦
	$('#addStandardWindow').window("open").window('setTitle', '添加销售员');
	$("input[name='sId']").val('-1');
}

function getQueryParams(queryParams) {  
	var searchcontent = $('#searchcontent').val();
     queryParams.rsn = searchcontent;  
     return queryParams;  
   
 }  

 //增加查询参数，重新加载表格  
function loadgrid() {  
    //查询参数直接添加在queryParams中      
    var queryParams = $('#grid').datagrid('options').queryParams;  
    getQueryParams(queryParams);  
    $('#grid').datagrid('options').queryParams = queryParams;  
    $("#grid").datagrid('load');  
}  
 
function doSearch(){
	
	loadgrid();
}

function doVersionchange() {  
	
    // 返回被选中的行 然后集成的其实是 对象数组  
    var row = $('#grid').datagrid('getSelections'); 
    if (row.length== 0) {  
    	$.messager.alert("提示", "<br>请选择设备", "info");  
    }else{
    	 
	    var snString = "";  
	    for(var i = 0;i<row.length;i++){  
	    
	    	snString += row[i].rsn+":"+row[i].rVersion;  
	        if(i < row.length-1){  
	        	snString += ','; 
	        }else{  
	            break;  
	        }  
	    }
	    alert(snString)
	   location.href="${pageContext.request.contextPath}/page.changeVersionDetails.ashx?sns="+snString+"&length="+row.length;
	    
    }  
}



//定义列
var columns = [ [ 
 { field:'ck',checkbox:true 
},  {
	field : 'rName',
	title : '产品名称',
	width : 120,
	
},{
	field : 'rsn',
	title : 'SN地址',
	width : 120,	
	
},{
	field : 'rMac',
	title : 'MAC地址',
	width : 120,
	
},{
	field : 'rState',
	title : '状态',  
	width : 160,
	
	formatter:formatterrState
	
},{
	field : 'rVersion',
	title : '版本',  
	width : 160,
	
	formatter:formatterrVersion
	
},{
	field : 'rSellTime',
	title : '出库时间',
	width : 160,
	
	formatter:formatterDate
}] ];


function formatterrSeller(value,row,index){
	if(value){
		return value.sName;
	}else{
		return;
	}
}

function formaterCaozuo(value,row,index){
	if(row.rState==0){
		return "<a onclick=doSingleOutput("+index+") href=#>出库</a>";
	}
	
}
function formatterDate(value,row,index){
	if(value==''||null==value){
		return '';
	}
	var now = new Date(parseInt(value) * 1000);  
	var year=now.getYear()+1900; 
	var month=now.getMonth()+1; 
	var date=now.getDate(); 
	var hour=now.getHours(); 
	var minute=now.getMinutes();
	minute= (minute > 9) ? minute=minute : minute='0'+minute;
	//var second=now.getSeconds(); 
	return year+"-"+month+"-"+date+" "+hour+":"+minute; 
}


function formatterrState(value,row,index){

	if(value==1){
		return "<font color='red'>出库</font>";
	}
	else if(value==0){
		return "库存";
	}else if(value==2){
		return "申请SN";
	}
}
function formatterrVersion(value,row,index){

	if(value==0){
		return "基础版";
	}
	else if(value==1){
		return "高定版";
	}else if(value==2){
		return "团装版";
	}else if(value==3){
		return "体验版";
	}
}

$(function(){
	$('#add').click(doAdd);
	$('#search').click(doSearch);
	$('#versionchangebtn').click(doVersionchange);
});
$(function(){
	// 先将body隐藏，再显示，不会出现页面刷新效果
	$("body").css({visibility:"visible"});
	
	// 收派标准数据表格
	$('#grid').datagrid( {
		iconCls : 'icon-forward',
		fit : true,
		border : false,
		rownumbers : true,
		singleSelect:true,
		striped : true,
		toolbar : '#tb',
		url : "${pageContext.request.contextPath}/page.selleroutputrulerlist.ashx",
		idField : 'rId',
		columns : columns,
		pageList: [30,50,100],
		pagination:true,
		view:myview,
		emptyMsg:"<font size=6>暂无记录</font>",
		singleSelect: false,
		selectOnCheck: true,
		checkOnSelect: true,
		queryParams:{rState:1}
	});
	
});



var myview = $.extend({},$.fn.datagrid.defaults.view,{
	onAfterRender:function(target){
		$.fn.datagrid.defaults.view.onAfterRender.call(this,target);
		var opts = $(target).datagrid('options');
		var vc = $(target).datagrid('getPanel').children('div.datagrid-view');
		vc.children('div.datagrid-empty').remove();
		if (!$(target).datagrid('getRows').length){
			var d = $('<div class="datagrid-empty"></div>').html(opts.emptyMsg || 'no records').appendTo(vc);
			d.css({
				position:'absolute',
				left:0,
				top:50,
				width:'100%',
				textAlign:'center'
			});
		}
	}
});

function load(){
	$('#searchcontent').focus();
}

</script>	

</head>
<body class="easyui-layout" onload="load()" >
	<div region="center">
	
		<table id="grid">
		
		</table>
	</div>
	

	
	<div id="tb" style="padding:5px;height:auto">
		<div style="margin-bottom:5px">
		
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SN: <input onkeydown=keyDown(event)  id="searchcontent" class="easyui-textbox" style="width:180px" >
			<a href="#"  id="search" class="easyui-linkbutton" iconCls="icon-search">查询</a>
			
			<a href="#"  id="versionchangebtn" class="easyui-linkbutton" iconCls="icon-ok" >版本变更</a>
			
		</div>
	</div>
</body>
<script type="text/javascript">
function keyDown(e) {
	var ev= window.event||e;
	//13是键盘上面固定的回车键
	if (ev.keyCode == 13) {
		//你要执行的方法
		doSearch();
	}
} 

</script>
</html>